﻿using RealtorsPortal.Entities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace RealtorsPortal.Data_Access_Layer
{
    public class AdsImagesDAL
    {
        DataAccessHelper daAccHelp = new DataAccessHelper();

        public DataTable GetImageUrlById(AdsImages adsObj)
        {
            List<SqlParameter> paraList = new List<SqlParameter>();
            SqlParameter para;

            para = new SqlParameter("@AdvId", SqlDbType.Int);
            para.Value = adsObj.AdvId;
            paraList.Add(para);

            return daAccHelp.GetData("sp_Get_ImageUrl_ByAdvId", paraList);
        }

        public int UpdateAdsImage(AdsImages adsObj)
        {
            DataTable dt = new DataTable();
            List<SqlParameter> paraList = new List<SqlParameter>();
            SqlParameter para;

            para = new SqlParameter("@Id", SqlDbType.Int);
            para.Value = adsObj.Id;
            paraList.Add(para);
            para = new SqlParameter("@AdvId", SqlDbType.Int);
            para.Value = adsObj.AdvId;
            paraList.Add(para);
            para = new SqlParameter("@ImageUrl", SqlDbType.NVarChar);
            para.Value = adsObj.ImageUrl;
            paraList.Add(para);

            return daAccHelp.ExcuteStoredNonQuery("sp_Update_AdsImages", paraList);
        }

        public int InsertIntoAdsImage(AdsImages adsObj)
        {
            DataTable dt = new DataTable();
            List<SqlParameter> paraList = new List<SqlParameter>();
            SqlParameter para;

            para = new SqlParameter("@AdvId", SqlDbType.Int);
            para.Value = adsObj.AdvId;
            paraList.Add(para);
            para = new SqlParameter("@ImageUrl", SqlDbType.NVarChar);
            para.Value = adsObj.ImageUrl;
            paraList.Add(para);

            return daAccHelp.ExcuteStoredNonQuery("sp_Insert_AdsImages", paraList); ;
        }

        public int DeleteAdsImages(AdsImages adsObj)
        {
            DataTable dt = new DataTable();
            List<SqlParameter> paraList = new List<SqlParameter>();
            SqlParameter para;

            para = new SqlParameter("@AdvId", SqlDbType.Int);
            para.Value = adsObj.AdvId;
            paraList.Add(para);

            return daAccHelp.ExcuteStoredNonQuery("sp_Delete_AdsImages", paraList);
        }

        public int DeleteAdsImagesById(AdsImages adsObj)
        {
            DataTable dt = new DataTable();
            List<SqlParameter> paraList = new List<SqlParameter>();
            SqlParameter para;

            para = new SqlParameter("@Id", SqlDbType.Int);
            para.Value = adsObj.Id;
            paraList.Add(para);

            return daAccHelp.ExcuteStoredNonQuery("sp_Delete_AdsImages_ById", paraList);
        }

        public int GetNextID()
        {
            return daAccHelp.GetLastID("sp_GetAdvertisementsLastID", "AdvId");
        }

        public DataTable GetAdsImagesByAdvId(string advId)
        {
            string cmd = @"select ImageUrl from AdsImages where AdvId = "+ advId;
            return daAccHelp.GetDataTable(cmd);
        }
    }
}